/**
 * Created by cjh1 on 2016/8/15.
 */

// 搜索
$('.search-box .fa-angle-down').on('click', function () {
    $('#search-select').trigger('click');
});
$('#search-btn').on('click', function () {
    page.keyword = $('#search-input').val();
    doSearch();
});

/*$('#search-select').on('change', function () {
    page.searchType = $(this).val();
});*/
$('#tc-select').on('click', 'a', function (e) {
    e.preventDefault();
    page.searchType = $(this).data('value');
    $('#tc-select-text').text($(this).text());
});
function doSearch() {
    var url = '/common/search?type=' + page.searchType + '&key=' + page.keyword + '&area=' + page.searchArea
        + '&indus=' + page.searchIndustry;
    if (page.page) {
        url += '&page=' + page.page;
    }
    location.href = url;
}
// 支持回车键搜索
$('#search-input').on('keydown', function (e) {
    if (e.keyCode === 13) {
        page.keyword = $('#search-input').val();
        doSearch();
    }

});
/* 条件搜索 */
// 地区
$('#area-list').selectable({
    item: 'li',
    selected: function (e, item) {
        page.searchArea = $(item).data('value') || '';
        var keyword = $('#search-input').val();
        doSearch();
    }
});

// 行业
$('#industry-list').selectable({
    item: 'li',
    selected: function (e, item) {
        page.searchIndustry = $(item).data('value') || '';
        var keyword = $('#search-input').val();
        doSearch();
    }
});
// 分页
$('#page-list').on('click', '[data-page]', function (e) {
    e.preventDefault();
    page.page = $(this).data('page');
    doSearch();
})
